<!DOCTYPE html>
<head>
<base href="${ctx_path}/">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv=X-UA-Compatible content=IE=EmulateIE9>
<link rel="stylesheet" type="text/css" href="res/lib/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="res/lib/bootstrap/css/bootstrap-responsive.min.css">
<link rel="stylesheet" type="text/css" href="res/plugins/font-awesome/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="res/media/css/glyphicons.css">
<link rel="stylesheet" type="text/css" href="res/media/css/style.css">
<link rel="stylesheet" type="text/css" href="res/media/css/style-metro.css">
<link rel="stylesheet" type="text/css" href="res/media/css/comm.css">
<link rel="stylesheet" type="text/css" href="res/plugins/kindeditor/default/default.css">

<link rel="stylesheet" type="text/css" href="res/admin/css/splashy/splashy.css">

<link rel="stylesheet" type="text/css" href="res/plugins/ueditor/themes/default/css/ueditor.css">

<script data-main="res/media/main.js" src="res/require.js" ></script>
</head>
<body class="page-header-fixed" ng-controller="IndexCtrl">
<!--導航-->
<div id="navs" class="row-fluid">
	<div id="navs_area">
		<div class="pull-left">
			<ul>
				<li><a ui-sref="index" ui-sref-opts="{reload:true}">首 页</a></li>
				<!-- <li ><a href="res/media/module/blog/index.htm" target="_blank">博 客</a></li>-->
				<li ><a ui-sref="tools" ui-sref-opts="{reload:true}">在线工具</a></li>
				<li ><a ui-sref="games" ui-sref-opts="{reload:true}">娱乐</a></li>
				<li ><a ui-sref="about" ui-sref-opts="{reload:true}">关于我们</a></li>
			<!--  	<li ><a ui-sref="news" ui-sref-opts="{reload:true}">新闻</a></li> -->
			</ul>
		</div>
		<div class="pull-right" ng-if="!isLogin">
			<ul>
				<li >
					<div class="input-append" style="margin-bottom:1px;">
						<input class="m-wrap" style="width:160px;height:17px;margin-top:3px" type="text" id="search" placeholder="输入搜索内容"> &nbsp
						<button class="btn green" style="height:31px;margin-top:3px" type="button" ng-click="search();"><i class="icon-search m-icon-white"></i></button>
					</div>
				</li>
				<li><a data-toggle="modal" href="#login_modal">登 陆 </a></li>
				<li ><a ui-sref="index.register" >注 册 </a></li>
			</ul>
		</div>
		<div class="pull-right" ng-if="isLogin">
			<ul>
				<li >
					<div class="input-append" style="margin-bottom:0px;margin-right:10px;">
						<input class="m-wrap" style="width:160px;height:17px;margin-top:3px" type="text" id="search" placeholder="输入搜索内容"> &nbsp
						<button class="btn green" style="height:31px;margin-top:3px" type="button" ng-click="search();"><i class="icon-search m-icon-white"></i></button>
						<!-- <i class="splashy-zoom"></i>  -->
					</div>
				</li>
				<li>
					<a ui-sref="space({user_id:currentUser.id})" ui-sref-opts="{reload:true}" >你好， {{currentUser.user_name}}</a>
				</li>
				
				<!--  
				<li >
					<a ui-sref="space({user_id:currentUser.id})" ui-sref-opts="{reload:true}" >我的空间 </a>
				</li>
				-->
				<li >
					<a href="javascript:;" ng-click="logout()" >退出 </a>
				</li>
			</ul>
		</div>
	</div>
	
</div>
<div class="content">
	<!--   內容區-->
	<div ui-view="body"></div>
	<!-- 版权 -->
	<div ui-view="foot"></div>
	
	<!--登陆-->
	<div id="login_modal" class="modal hide fade" tabindex="-1" data-width="760">

		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
			<h3>会员登陆</h3>
		</div>

		<div class="modal-body">

			<div class="row-fluid">
				<div class="alert alert-error" ng-show="showError" >
					用户名或密码错误!
				</div>
				<form class="form-horizontal" ng-submit="login();" name="loginForm" novalidate="novalidate">
					<div class="control-group">
						<label class="control-label">
							邮箱:
							<span class="required">*</span>
						</label>
						<div class="controls">
							<input type="text" class="span6 m-wrap" required ng-model="user.email" name="email">
							<span class="error help-inline" ng-show="loginForm.email.$error.required">请输入邮箱地址</span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">
							密码:
							<span class="required">*</span>
						</label>
						<div class="controls">
							<input type="password" class="span6 m-wrap" required ng-model="user.password" name="password">
							<span class="error help-inline" ng-show="loginForm.password.$error.required">请输入密码</span>
						</div>

					</div>

					<div class="form-actions">
						<button type="submit" ng-disabled="loginForm.$invalid" class="btn purple">登陆</button>
						<button type="button" data-dismiss="modal" class="btn">取消</button>

					</div>
				</form>
			</div>

		</div>

	</div>
</div>
<script type="text/javascript">
require([
         'app'
],function(app){
	app.controller('IndexCtrl',['$scope','$state' , '$rootScope','checkUser', '$http', function($scope,$state,$rootScope, checkUser, $http){
		$scope.showError = false;	// 显示错误信息
		$scope.login = function(){
			$http({method:'post',url:"login", params:$scope.user}).success(function(result){
				
				if(result.status == 1){
					$scope.showError = false;
					$("#login_modal").modal('hide');
					checkUser.login(result.user);
				}else{
					$scope.showError = true;
				}
			}).error(function(){
				alert("网络连接失败");
			});
		};
		
		$scope.logout = function(){
			if(confirm("确定退出？")){
				$("input[name='email']").val("");
				$("input[name='password']").val("");
				$http({method:'post',url:"logout"}).success(function(result){
					checkUser.logout();	
					$state.go("index.topicAll",{}, {reload:true, inherit: true});
				}).error(function(){
					alert("网络连接失败");
				});
			}
		};
		// 搜索
		$scope.search = function(){
			var search = $("#search").val();
			//var tilte=$("#loadTitle").find("li[class='active']").attr("id");
			var params = {"search":search};
			$state.go("index.topicAll",params, {reload:true, inherit: true});
		};
	}]);
	
	
	
	// 检测用户是否登录 service
	app.factory('checkUser', ['$rootScope','$cookieStore', function($rootScope, $cookieStore){
		
		var currentUser = '${current_user?default("")}';
		if(currentUser){
			$rootScope.isLogin = true;
			$rootScope.currentUser = angular.fromJson(currentUser);
		}else{
			$rootScope.isLogin = false;
		}
		return {
			login:function(user){
				$rootScope.isLogin = true;
				$rootScope.currentUser = user;
				
			},
			logout: function(){
				$rootScope.isLogin = false;
				$rootScope.currentUser = null;
			},
			isLogin: function(){
				return $rootScope.isLogin;
			},
			update: function(user){
				angular.copy(user, $rootScope.currentUser);
			},
			getUser: function(){
				return $rootScope.currentUser;
			}
		};
		
	}]);
	
});
</script>
</body>
